package com.tengju.data.domain.model.user;

import com.fasterxml.jackson.annotation.JsonCreator;
import com.fasterxml.jackson.annotation.JsonFormat;
import com.fasterxml.jackson.annotation.JsonValue;
import lombok.AllArgsConstructor;
import lombok.Getter;

import java.util.List;

@Getter
@JsonFormat(shape = JsonFormat.Shape.OBJECT)
@AllArgsConstructor
public enum StarLevelEnum {
    NONE(0,StarRoleEnum.NONE,"经销商","无星"),
    CITY_STAR_ONE(10, StarRoleEnum.SERVICE_PROVIDER,"1星","城市服务商1星"),
    CITY_STAR_TWO(20, StarRoleEnum.SERVICE_PROVIDER,"2星","城市服务商2星"),
    CITY_STAR_THREE(30, StarRoleEnum.SERVICE_PROVIDER,"3星","城市服务商3星"),
    CITY_STAR_FOUR(40, StarRoleEnum.SERVICE_PROVIDER,"4星","城市服务商4星"),
    EC(50, StarRoleEnum.OPERATOR,"EC","大区运营商"),
    SEC(60, StarRoleEnum.OPERATOR,"SEC","大区运营商"),
    EEC(70, StarRoleEnum.OPERATOR,"EEC","大区运营商");

    private Integer code;
    private StarRoleEnum starRoleEnum;
    private String desc;
    private String appShowName;

    @JsonCreator
    public static StarLevelEnum parseByStarLevel(Integer starLevel) {
        if (starLevel == null) {
            return null;
        }

        for (StarLevelEnum type : values()) {
            if (type.code.equals(starLevel)) {
                return type;
            }
        }
        return null;
    }

    public StarRoleEnum parseRoleByLevel() {
        if (this == CITY_STAR_ONE || this == CITY_STAR_TWO || this == CITY_STAR_THREE || this == CITY_STAR_FOUR) {
            return StarRoleEnum.SERVICE_PROVIDER;
        }
        if (this == EC || this == SEC || this == EEC) {
            return StarRoleEnum.OPERATOR;
        }
        return StarRoleEnum.NONE;
    }

    public static List<StarLevelEnum> getAll() {
        return List.of(StarLevelEnum.NONE,StarLevelEnum.CITY_STAR_ONE,
                StarLevelEnum.CITY_STAR_TWO,StarLevelEnum.CITY_STAR_THREE,
                StarLevelEnum.CITY_STAR_FOUR,StarLevelEnum.EC,
                StarLevelEnum.SEC,StarLevelEnum.EEC);
    }

    public boolean isServiceStarLevel(){
        return this.getCode() > NONE.getCode();
    }

    @JsonValue
    public Integer getCode() {
        return code;
    }
}
